<template>
  <div class="score-block">
    <div class="score-title" :class="approvalProcess > 3 ? '':'mb16'">评分结果表</div>
    <div class="score-container" v-if="approvalProcess > 3">
      <span>总分： {{ total }}</span>
      <span>成熟度等级： {{ allGrade  }}</span>
    </div>
    <div class="score-con">
      <score-table2  :data="tableData" :approvalProcess="approvalProcess" @go-last="handleGoLast" @go-next="handleGoNext" ></score-table2>
      <!-- <score-table v-else :assessId="assessId" :draftdata="tableDraftData" @go-last="handleGoLast" @go-save="handleGoSave" @go-next="handleGoNext"></score-table> -->
    </div>
  </div>
</template>

<script setup>
//  import ScoreTable from '@/views/components/table/ScoreTable.vue';
 import ScoreTable2 from '@/views/components/table/ScoreTable2.vue';
 import { getApprovalScore, getConfirmScore } from '@/api/sjhg/approval'; 
 import { useRouter } from 'vue-router'
import { MessagePlugin } from 'tdesign-vue-next';

const router = useRouter()

 const props = defineProps({
  assessId: {
    type: Number,
    default: ''
  },
  approvalProcess: {
    type: Number,
    default: 0
  },
})

//-------------------------------评分结果 上一步  下一步------------------------------------------------
const emit = defineEmits(["goReport","goAudit"]);
 //下一步  到上传报告
 const handleGoNext = () =>{ 
   getConfirmScore({assessId: props.assessId})
      .then((res) => {
        if (res.code == 200) {
          emit('goReport')
        } else {
          MessagePlugin.error(res.msg);
        }
   });
}
//上一步
const handleGoLast = () => {
  emit('goAudit')
}
//---------------------------------------------------评分详情------------------------------------

const tableData = ref([])
const tableDraftData = ref([])
const total = ref(0)
const allGrade = ref('-')
onMounted(() => {
  if(props.assessId && props.approvalProcess > 2){
    console.log('===Score 审核侧 onMounted==')
    getScore();
  }
})
const getScore = () => {
    let params = {}
    params.assessId = props.assessId
    getApprovalScore(params)
      .then((res) => {
        if (res.code == 200) {
          if(res.data?.isDraft == 0){//保存草稿的数据
            const list = res.data?.extra
            tableDraftData.value = JSON.parse(list)
          }else if(res.data?.isDraft == 1){  
            const list = res.data?.extra
            if(list){
              tableData.value = JSON.parse(list)
              if(tableData.value?.length>0){
                total.value = tableData.value[0].total
                allGrade.value = tableData.value[0].allGrade
              }
            }
          }
        } 
      }).finally(() => {
      });
  }
</script>

<style lang="scss" scoped>
.score-block{
  position: relative;
  height: calc(100vh - 328px);
  margin-bottom: 80px;
}
.mb16{
  margin-bottom: 16px;

}
.score-con{
  height: 100%;
  position: sticky;
  top: 0;
  overflow-y: auto;
}
</style>